﻿<?php
@session_start();
	include '../templates/db/db.php';
?>
<div id="information">
	<div id='pic_user' style='float: left;margin-top: 20px;'>
	<?php
			$username=$_SESSION['username'];
			$select_user=mysql_query('SELECT * FROM users WHERE username="'.$username.'"');
			$row_user=mysql_fetch_assoc($select_user);
			if(mysql_num_rows($select_avatar)==1){
					  $img="<img src='../user_pics/".$row_avatar[pic_name]."' width='130' height='130' style='border: 2px solid black;box-shadow: 5px 5px 5px #000' alt='avatar'/>";
			}
			else{
				  $img="<img src='../user_pics/default.png' width='130' height='130' style='border: 2px solid black;box-shadow: 5px 5px 5px #000' alt='avatar'/>";
			}
			echo '<p style="height: 240px; width: 142px; border-right: 1px solid #000;">'.$img.'</p>';
	?>
	</div>
	<div id='write'>
			<div class='boxx'>
				<form method='post' action=''>
					<table><tr>
						<td><input type='text' name='post_user' id='post_user' /></td>
						<td><input type='submit' name='submit' id='submit_ajax' value='Запиши' /></td>
					</tr></table>
				</form>
				<?php
				    if($_POST['submit']==true){
					$text = htmlspecialchars(trim($_POST['post_user']));
					$date = time();
					$username = $_SESSION['username'];
					
					$select_note = mysql_query('SELECT * FROM notes WHERE username="'.$username.'" && text="'.$text.'"');
					$broi=mysql_num_rows($select_note);
					
					if($broi == 0 && strlen($text) > 1){
					   $db_res= 'INSERT INTO notes(`username`, `text`, `date`) VALUES("'.$username.'", "'.$text.'", "'.$date.'")' or die(mysql_error());
						$db_res_q = mysql_query($db_res) or die(mysql_error());
					} else {
					?>
						<script type='text/javascript'>
							alert('Тази записка я имате или този запис е много къс !');						
						</script>
					<?php
					}
					}
				?>
			</div>
			
			<br />
			<hr width='90%' />
			<br />
			
			<div id='chatBox'></div>
			
	</div>
</div>